import 'package:flutter/material.dart';
import 'package:flutter_cwhisky/component/text_view.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';


import '../../common/style/colors.dart';
import '../../component/base/base_state_less_view.dart';
import '../../component/ink/ink_well_custom.dart';
import 'search_logic.dart';

class SearchPage extends BaseStateLessView<SearchLogic> {
  const SearchPage({super.key});

  @override
  Widget buildContent(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: BackButton(
          color: AppColors.primary,
        ),
        leadingWidth: 24,
        elevation: 0,
        backgroundColor: AppColors.white,
        title:TextView(text: "121",),
      ),
      body: Container(
        child: Column(
          children: [ _buildTab()],
        ),
      ),
    );
  }

  // _buildHistory() {
  //   final list = controller.historys
  //       .map((e) => InkWellCustom(
  //               child: TagView(
  //             item: e,
  //           )))
  //       .toList();
  //   return Container(
  //     margin: EdgeInsets.symmetric(horizontal: 12.w),
  //     child: Column(
  //       children: [
  //         Row(
  //           mainAxisAlignment: MainAxisAlignment.spaceBetween,
  //           children: [
  //             TextView(
  //               text: '历史搜索',
  //               fontWeight: FontWeight.bold,
  //               fontSize: 16.sp,
  //             ),
  //             IconButton(
  //               onPressed: () {},
  //               icon: Icon(Icons.delete),
  //               iconSize: 18.r,
  //             )
  //           ],
  //         ),
  //         Wrap(
  //           runSpacing: 10,
  //           spacing: 10,
  //           children: list,
  //         )
  //       ],
  //     ),
  //   );
  // }

  _buildTab() {
    var map = controller.tabs
        .map((e) => Tab(
      text: e,
    ))
        .toList();
    return Expanded(
        child: Column(
      children: [
        Container(
          height: 45.h,
          width: double.maxFinite,
          decoration: BoxDecoration(
              borderRadius: BorderRadius.only(topLeft: Radius.circular(12), topRight: Radius.circular(12)),
              gradient: LinearGradient(
                  begin: Alignment.topCenter,
                  end: Alignment.bottomCenter,
                  colors: [AppColors.primary.withAlpha(50), AppColors.primary.withAlpha(0)])),
          child:  TabBar(
            indicatorPadding: const EdgeInsets.symmetric(horizontal: 6),
            indicatorSize: TabBarIndicatorSize.label,
            indicatorColor: AppColors.primary,
            labelStyle: TextStyle(color: AppColors.colorTextMain, fontSize: 16.sp, fontWeight: FontWeight.w500),
            labelColor: AppColors.colorTextMain,
            unselectedLabelStyle: TextStyle(color: AppColors.colorTextSub, fontSize: 14.sp),
            unselectedLabelColor: AppColors.colorTextSub,
            tabs: map,
            padding: EdgeInsets.zero,
            indicator: UnderlineTabIndicator(
              insets: EdgeInsets.symmetric(horizontal: 12),
                borderRadius: BorderRadius.circular(4), borderSide: const BorderSide(width: 2.0, color: AppColors.primary)),
            labelPadding: EdgeInsets.symmetric(horizontal: 12.w),
            controller: controller.tabController,
            splashBorderRadius: BorderRadius.circular(4.r),
          ),
        ),
        Expanded(
            child: ListView.builder(
          itemCount: 10,
          itemBuilder: (context, index) {
            Color color = AppColors.colorTextSub;
            switch (index) {
              case 0:
                color = Colors.red;
                break;
              case 1:
                color = Colors.yellow;
                break;
              case 2:
                color = Colors.tealAccent;
                break;
            }
            return Container(
              margin: EdgeInsets.symmetric(horizontal: 12.w),
              padding: EdgeInsets.symmetric(vertical: 12.h),
              child: Row(
                children: [
                  Container(
                      margin: EdgeInsets.only(right: 12.w),
                      alignment: Alignment.center,
                      width: 18.r,
                      height: 18.r,
                      decoration: BoxDecoration(color: color, borderRadius: BorderRadius.circular(4)),
                      child: TextView(
                        text: "${index + 1}",
                        fontSize: 10.sp,
                        fontColor: AppColors.white,
                      )),
                  TextView(text: '励志中年人自救站' + index.toString())
                ],
              ),
            );
          },
        ))
      ],
    ));
  }
}
